use strict;
use warnings;
use Data::Dumper;
use Test::More 'no_plan';

use testsupport  ;

use_ok('Log');

# my $log = Log->new( level => 'DEBUG' , debuglevel => 3);

my $log = Log->instance;
$log->setlevels('DEBUG',3);

is($log->xwarning($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "warn");
is($log->xinfo($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "info");
is($log->xdebug(1,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "debug1");
is($log->xdebug(2,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "debug2");
is($log->xdebug(3,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "debug3");
is($log->xdebug(4,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "debug4");
is($log->xdump(3,"provadump",{ 'test' => 'dump' }),1,"dump");
is($log->xerror($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "error");

eval {
    is($log->xsupererror("8c11dac3-127c-31f6-bd97-a548be67f8cf",
			 ,$log->format(__FILE__,__LINE__,"errore")),1,"log error 6.1");
};
check_uuid(__FILE__,__LINE__,"8c11dac3-127c-31f6-bd97-a548be67f8cf",$@);


eval {
    is($log->xfatal("0033ed40-0d77-36e2-b3f1-2dcda1760a16",
		    $log->format(__FILE__,__LINE__,lorem)),1,"fatal");
};
check_uuid(__FILE__,__LINE__,"0033ed40-0d77-36e2-b3f1-2dcda1760a16",$@);


eval {
    is($log->xinternal("5679d396-4088-321a-8603-a0ebcfcdc38b",
		       ,$log->format(__FILE__,__LINE__,lorem)), 1 , "internal");
};
check_uuid(__FILE__,__LINE__,"5679d396-4088-321a-8603-a0ebcfcdc38b",$@);

# $log = Log->new( level => 'INFO');
$log->setlevels('INFO');

is($log->xinfo($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "INFO/info");
is($log->xwarning($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "INFO/warn");
is($log->xerror($log->u(),$log->format(__FILE__,__LINE__,lorem)), 1 , "INFO/error");
eval {
    is($log->xfatal("7e406168-c076-3354-a4b9-3b511db969d4",
		    ,$log->format(__FILE__,__LINE__,lorem)),1,"INFO/fatal");
};
check_uuid(__FILE__,__LINE__,"7e406168-c076-3354-a4b9-3b511db969d4",$@);

eval {
    is($log->xfatal($log->nou,
		    ,$log->format(__FILE__,__LINE__,lorem)),1,"INFO/nou");
};
check_uuid(__FILE__,__LINE__,"00000000-0000-0000-0000-000000000000",$@);


is($log->xdebug(0,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "INFO/debug0");
is($log->xdebug(100,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "INFO/debug100");

# $log = Log->new( level => 'NO');
$log->setlevels('NO');


is($log->xinfo($log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "NO/info");
is($log->xwarning($log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "NO/warn");
is($log->xdebug(1,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "NO/debug");
is($log->xdebug(100,$log->u(),$log->format(__FILE__,__LINE__,lorem)), 0 , "NO/debug100");

eval {
    is($log->xinternal("eedf3c58-4c8b-39f2-9736-1bd05da23fa7",
		       $log->format(__FILE__,__LINE__,lorem)), 0 , "NO/internal");
};
check_uuid(__FILE__,__LINE__,"eedf3c58-4c8b-39f2-9736-1bd05da23fa7",$@);

eval {
    $log->setlevels('DEBU',1);
};
ok($@ ne '',"DEBU");

eval {
    $log->setlevels('DEBUG',"no num");
};
ok($@ ne '',"debug level no numeric");

eval {
    $log->setlevels('DEBUG');
    is($log->debuglevel,3,"DEBUG is default 3?");
};
ok($@ eq '',"DEBUG is default");

eval {
    $log->setlevels();
};
ok($@ eq '',"setlevel default");
is($log->debuglevel,3,"DEBUG is default 3?");
is($log->level,"FATAL","level is default FATAL (default)?");

eval {
    $log->setlevels('DEBUG',0);
};
ok($@ eq '',"DEBUG 0");

eval {
    $log->setlevels('DEBUG',-1);
};
ok($@ ne '',"DEBUG -1");


my $trace = $log->get_printable_stack();
print STDERR $trace;
$trace = $log->get_printable_filtered_stack();
print STDERR $trace;














